import Taro from '@tarojs/taro'
import React, { Component } from 'react'
import { View, Map } from '@tarojs/components'
import './index.scss'

type pageProps = {}

type pageState = {
  /**经度 */
  _longitude: number
  /**纬度 */
  _latitude: number
}

class MapPage extends Component<pageProps, pageState> {
  state: pageState = {
    _longitude: 1,
    _latitude: 2
  }
  componentDidMount() {
    const self = this
    Taro.getLocation({
      success(res) {
        self.setState({
          _longitude: res.longitude,
          _latitude: res.latitude
        })
      }
    })
  }
  onTap() {}
  render() {
    const { _longitude, _latitude } = this.state
    return (
      <View className='map-page'>
        <Map
          id='1'
          onClick={this.onTap.bind(this)}
          longitude={_longitude}
          latitude={_latitude}
          show-location
          show-compass
          show-scale
          circles={[
            {
              latitude: _latitude,
              longitude: _longitude,
              color: '#FF0000DD',
              radius: 300,
              fillColor: '#7cb5ec88',
              strokeWidth: 0.5
            }
          ]}
          style='width:100%;height:100%'
        ></Map>
      </View>
    )
  }
}

export default MapPage
